/**
 * @Author 韦建韩
 * @Date 2022/5/18
 */
package com.example.demo;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;

@RestController
public class HelloWorldController {
    @RequestMapping("hello")
    public String helloWorld(){
        return "helloWorld";
    }
    @RequestMapping("shell")
    public String shell() throws IOException, InterruptedException {
        Process  p = Runtime.getRuntime().exec("/java/shell/test1.sh");
        BufferedReader bufferedReader = new BufferedReader(
                new InputStreamReader(p.getInputStream(), StandardCharsets.UTF_8));
        String line ;
        StringBuilder s = new StringBuilder();
        while ((line = bufferedReader.readLine()) != null) {
          s.append(line);
        }
        p.waitFor();
        return s.toString();
    }
}
